/**
 * Copyright (C) 2010 kt innotz Co., Ltd. All rights reserved.
 */
package com.kt.paas.prov.iaas.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.kt.paas.prov.iaas.worker.RequestIaaSWorker;

/**
 * Created on 2011. 2. 18.
 * <p>Title : RequestIaasController.java</p>
 * <p>@author : kobe </p>
 * <p>Description : </p>
 * 
 *
 */
@Controller
public class RequestIaasController {

	private static final Logger logger = LoggerFactory.getLogger(RequestIaasController.class);
	
	@Autowired
	RequestIaaSWorker worker;
	
	public String restoreVM() {
		logger.info("======== Request iaas ==========");
		logger.info("stop vm");
		
		// TODO 
		
		
		return "restore";
	}
	
	@RequestMapping(value="/deploy", method=RequestMethod.GET)
	public String deployVM() {
		logger.info("======== Request iaas ==========");
		logger.info("deploy vm");
		
		try {
			worker.deployVM();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "deploy";
	}
	
	@RequestMapping(value="/stop", method=RequestMethod.GET)
	public String stopVM() {
		logger.info("======== Request iaas ==========");
		logger.info("stop vm");
		
		try {
			worker.stopVM("699");  // credential 에서 가져와야 할 듯? context? 아무튼 vmid를 받아서 처리해야 함.
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "stop";
	}
	
	@RequestMapping(value="/destory", method=RequestMethod.GET)
	public String destroy() {
		logger.info("======== Request iaas ==========");
		logger.info("Delete vm");
		
		try {
			worker.destroyVM("703");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "destory";
	}
}
